package com.meilai.project.controller.web.business.installOrder;


import com.meilai.project.dto.CommonResult;
import com.meilai.project.dto.business.installOrder.WorkOrderReportInfoDTO;
import com.meilai.project.service.business.installOrder.ManyWorkOrderReportService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 多工单导出报告表 前端控制器
 * </p>
 *
 * @author xhy
 * @since 2022-08-03
 */
@RestController
@RequestMapping("api/web/manyWorkOrderReport")
public class ManyWorkOrderReportController {

    @Autowired
    private ManyWorkOrderReportService manyWorkOrderReportService;

    @PostMapping("/generateReport")
    @ApiOperation("多个工单生成报告")
    public CommonResult generateReport(@RequestBody WorkOrderReportInfoDTO dto) {
        try {
            Runnable runnable = () -> {
                manyWorkOrderReportService.generateReport(dto);
            };
            new Thread(runnable).start();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new CommonResult().successForMessage("后台正在生成报告，请稍后打开多工单报告列表页进行下载");
    }

    @GetMapping("/page")
    @ApiOperation("列表页")
    public CommonResult page(@RequestParam(value = "page", defaultValue = "1") Integer page,
                             @RequestParam(value = "page_size", defaultValue = "10") Integer page_size,
                             @RequestParam(value = "order_id", required = false) Long order_id) {
        return new CommonResult().success(manyWorkOrderReportService.page(page, page_size, order_id));
    }
}

